home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # samba-share.cgi
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: samba-share.frm,v 1.7 1997/06/19 22:26:35 shotes Exp $
-
- require "/usr/OnRamp/lib/OnRamp.pm";
- require "/usr/OnRamp/lib/java.pm";
-
- $conf = "/usr/local/samba/lib/smb.conf";
- $dummy = "/usr/local/samba/lib/smb.conf.tmp";
- $myname = "samba-share.cgi";
- $title = "SAMBA Shares";
-
- $js_main = "
- type = \"share\";
- $js_account_main;
- $js_error_box;
- $js_filename;
- function testAdd(form) {
- if (form.new_account.value.length == 0) {
- errorBox(form.new_account, \"To create a new share, enter\\n\"
- + \"the new share name and click\\n\"
- + \"the add button.\");
- return (false);
- }
- if (!testSambaName(form.new_account)) return (false);
- return (true);
- }
- function testSambaName(Ctrl) {
- if (!testFileChars(Ctrl.value)) {
- errorBox(Ctrl, \"The share name cannot contain meta \"
- + \"characters.\");
- return (false);return (false);
- }
- word = Ctrl.value;
- if (word.indexOf(' ', 0) != -1 || word.indexOf('\t', 0) != -1) {
- errorBox(Ctrl, \"The share name cannot contain whitespace \"
- + \"characters.\");
- return (false);
- }
- return (true);
- }";
-
- $js_edit =
- "$js_standard;
- $js_error_box;
- $js_filename;
- function checkForm(form) {
- if (form.new_name && !testSambaName(form.new_name)) return (false);
- if (form.comment.value.length > 0 && !testFileChars(form.comment.value)) {
- errorBox(form.comment, \"The comment cannot contain \"
- + \"meta characters.\");
- return (false);
- }
- if (form.path.value.length == 0) return (true);
- if (!testFilename(form.path, \"path\")) return (false);
- return (true);
- }
- function testSambaName(Ctrl) {
- if (!testFileChars(Ctrl.value)) {
- errorBox(Ctrl, \"The share name cannot contain meta \"
- + \"characters.\");
- return (false);
- }
- word = Ctrl.value;
- if (word.indexOf(' ', 0) != -1 || word.indexOf('\t', 0) != -1) {
- errorBox(Ctrl, \"The share name cannot contain whitespace \"
- + \"characters.\");
- return (false);
- }
- return (true);
- }";
-
-
- print "Content-type: text/html\n\n";
-
- if ( ! -e "/usr/etc/ppp" ) {
- &title_block($title);
- &header_block($title);
- print "<i>SAMBA software not installed. Install subsystem
- </i><b>fw_samba.sw.base</b><i> from the freeware CD.</i>";
- exit 0;
- }
-
- &get_fields;
-
- &getAccounts;
-
- if (%fld) {
- $fld{'chosen'} =~ /([\w.-]+)/;
- $fld{'chosen'} = $1;
-
- $help = $document_root . $ENV{"SCRIPT_NAME"};
- $help =~ s/cgi$/hlp/;
- exec $help if ($fld{'help'} eq "Help");
-
- if ($fld{'add'}) {
- &error(2,"Share name required.") if !$fld{'new_account'};
- &error(2,"Invalid share name.")
- if $fld{'new_account'} =~ /$METACHARS/o || $fld{'new_account'} =~ /\s/;
- $fld{'chosen'} = $fld{'new_account'};
- $fld{'mode'} = "add";
- $val{'public'} = "No";
- $val{'writeable'} = "No";
- $val{'printable'} = "No";
-
- &editAccount;
- }
- elsif ($fld{'delete'}) {
- &error(2,"To delete an existing share, first select a share from "
- . "list, then click the delete button.") if !$fld{'chosen'};
- $message = qq|Click "Ok" to save changes.|;
- &generic($fld{'chosen'});
- }
- elsif ($fld{'edit'}) {
- &error(2,"To edit an existing share, first select a share from "
- . "list, then click the edit button.") if !$fld{'chosen'};
- &get_vals($fld{'chosen'});
- $fld{'mode'} = "edit";
- &editAccount;
- }
- elsif ($fld{'doedit'}) {
- if ($fld{'mode'} eq "add") { &doAdd; }
- else { &doEdit; }
- &restart;
- &getAccounts;
- &generic;
- }
- elsif ($fld{'doit'}) { &tryToDelete; &restart; &getAccounts; &generic; }
- else { $message = "Use buttons to submit form."; $val{'new_account'} = $fld{'new_account'}; &generic; }
- } else { &generic; }
-
- sub error {
- &error_block($_[1]);
- %val = %fld;
- if ($_[0] == 0) { &addAccount; }
- elsif ($_[0] == 1) { &editAccount; }
- else { &generic; }
- exit 0;
- }
-
- sub restart {
- $chk = system ("/etc/chkconfig", "samba");
- if (! $chk) {
- system("/etc/init.d/samba stop > /dev/null 2>&1");
- system("/etc/init.d/samba start > /dev/null 2>&1");
- }
- }
-
- sub doEdit {
- open(IN, "< $conf");
- open(OUT, "> $dummy");
-
- while(<IN>) {
- if ($_ =~ /\[$fld{'chosen'}\]/) {
- print OUT "[" . $fld{'new_name'} . "]\n";
-
- &print_share;
-
- $done = 0;
- while(!$done) {
- $in = <IN>;
- if ($in eq "" || $in =~ /\[.*\]/) {
- $done = 1;
- print OUT $in;
- }
- }
- } else { print OUT $_; }
- }
- close(IN);
- close(OUT);
- rename($dummy, $conf);
-
- $message = "Share edited.";
- }
-
- sub print_share {
- if ($fld{'comment'}) { print OUT " comment = $fld{'comment'}\n"; }
- if ($fld{'path'}) { print OUT " path = $fld{'path'}\n"; }
- if ($fld{'public'} eq "Yes") { print OUT " public = yes\n"; }
- if ($fld{'writeable'} eq "Yes") { print OUT " writeable = yes\n"; }
- if ($fld{'printable'} eq "Yes") { print OUT " printable = yes\n"; }
- print OUT "\n";
- }
-
- sub get_vals {
- $val{'public'} = "No";
- $val{'writeable'} = "No";
- $val{'printable'} = "No";
-
- open(IN, "< $conf");
- $read_lines = 0;
- while(<IN>) {
- if ($_ =~ /\[$fld{'chosen'}\]/) { $read_lines = 1; next; }
- elsif ($_ =~ /\[.*\]/) { $read_lines = 0; next; }
- next if $read_lines == 0;
- next if substr($_,0,1) eq ";";
-
- if ($_ =~ /(.*)=(.*)/) {
- $parm = $1;
- $value = $2;
-
- $parm =~ /^\s*([^\s].*[^\s])\s*$/; $parm = $1;
- $value =~ /^\s*([^\s].*)$/; $value = $1;
-
- if ($parm eq "public" && $value eq "yes") { $val{'public'} = "Yes"; }
- if ($parm eq "writeable" && $value eq "yes") { $val{'writeable'} = "Yes"; }
- if ($parm eq "read only" && $value eq "no") { $val{'writeable'} = "Yes"; }
- if ($parm eq "printable" && $value eq "yes") { $val{'printable'} = "Yes"; }
-
- if ($parm eq "comment" || $parm eq "path") {
- $val{$parm} = $value;
- }
- }
- }
- }
-
- sub editAccount {
- &js_title_block($title,$js_edit);
-
- &header_block("Edit SAMBA Share");
-
- print "$message<br>";
-
- print "<form name=StandardForm action=$myname method=post onSubmit=\"return runSubmit()\">";
-
- print "<input type=hidden name='chosen' value=$fld{'chosen'}>\n"
- . "<input type=hidden name='mode' value=$fld{'mode'}>\n";
-
- print "<center><table width=450>\n";
-
- if ($fld{'mode'} eq "edit") {
- print "<tr><th align=left>Share name:"
- . "<td>", &text("new_name", $fld{'chosen'}, 20), "</td></tr>\n";
- } else {
- print "<tr><th align=left>Share name:"
- . "<td><tt>$fld{'chosen'}</tt></td></tr>\n";
- }
-
- print "<tr><th align=left>Comment for share:"
- . "<td>", &text("comment", $val{'comment'}, 20), "</td></tr>\n";
-
- print "<tr><th align=left>Mount path of share:"
- . "<td>", &text("path", $val{'path'}, 20), "</td></tr>\n";
-
- print "<tr><th align=left>Allow public access?"
- . "<td><b>", &radio("public", $val{'public'}, "Yes", "No"), "</b></td></tr>\n";
-
- print "<tr><th align=left>Allow write privileges?"
- . "<td><b>", &radio("writeable", $val{'writeable'}, "Yes", "No"), "</b></td></tr>\n";
-
- print "<tr><th align=left>Is this a printing service share?"
- . "<td><b>", &radio("printable", $val{'printable'}, "Yes", "No"), "</b></td></tr>\n";
-
- print "</table></center><br>\n";
-
- print &js_buttons('doedit','Ok','onClick="markOK()"','onClick="markOther()"');
-
- print "</form></body></html>";
- }
-
- sub tryToDelete {
- if ($fld{'del_name'} eq "") { return; }
-
- open(IN, "< $conf");
- open(OUT, "> $dummy");
- while(<IN>) {
- if ($_ =~ /\[$fld{'del_name'}\]/) {
- while(<IN>) {
- if ($_ =~ /\[.*\]/) { print OUT $_; last; }
- }
- } else { print OUT $_; }
- }
- close(IN);
- close(OUT);
- rename($dummy, $conf);
-
- $message = "Share deleted.";
- }
-
- sub doAdd {
- open(OUT, ">> $conf");
-
- print OUT "\n[" . $fld{'chosen'} . "]\n";
- &print_share;
-
- close(OUT);
-
- $message .= "Share added.";
- }
-
- sub getAccounts {
- $i = 0;
- open(IN,"< $conf");
- while(<IN>) {
- if ($_ =~ /\[(.*)\]/) {
- next if $1 eq "global";
- $name[$i++] = $1;
- }
- }
- $number = $i;
- close(IN);
- }
-
- sub generic {
- &js_title_block($title,$js_main);
- &header_block($title);
-
- if (!$number && !$message) { $message = "No existing SAMBA shares."; }
- print "<i>$message</i>";
-
- print "<form name=AccountForm action=$myname method=post onSubmit=\"return runSubmit()\">";
-
- if ($_[0]) { print qq|<input type=hidden name="del_name" value=$_[0]>|; }
-
- if ($number) {
- print "<center><table width=400>";
-
- print qq|<tr><td><input type=submit name="add" value="Add New Share"|,
- qq| onClick="markAdd()"> |,
- qq|</td><td><input name="new_account" value="$val{'new_account'}" size=19></td></tr>|;
-
- print "<tr><td>";
- print qq|<input type=submit name="edit"
- value="Edit Selected Share" onClick="markEdit()"></td>|;
-
- undef @locList;
- for ($i=0;$i<$number;$i++) {
- if ($_[0] ne $name[$i]) { push(@locList,$name[$i]); }
- }
-
- print "<td rowspan=2>";
-
- print &choice_list(*locList,"chosen",20);
-
- print "</td></tr>";
-
- print qq|<tr><td><input type=submit name="delete"
- value="Delete Selected Share" onClick="markDelete()"></td></tr>|;
-
-
- print "</table></center><br>";
- } else {
- print "<center><table width=400>";
-
- print qq|<tr><td><input type=submit name="add" value="Add New Share" |,
- qq|onClick="markAdd()"> |,
- qq|</td><td><input name="new_account" value="$val{'new_account'}" size=19></td></tr>|;
-
- print "<tr><td>";
- print "</table>";
- }
-
- print &js_buttons('doit','Ok','onClick="markOther()"','onClick="markOther()"');
-
- print "</form></body></html>";
- }
-